package edu.hawaii.duedates;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;

import org.junit.Test;

/**
 * Test case for ErrorLogger methods.
 * @author Anthony M. Du
 *
 */

public class TestErrorLogger {
  // Test argument parameters.
  private final String[] args = {"-verbose", "-v", "arg1", "arg2"};
  /**
   * Test getOptions method.
   */
  @Test
  public void testGetOptions() {
    String[] opts = {"-verbose", "-v"};
    ErrorLogger erlog = new ErrorLogger(args);
    assertEquals("Testing number of options", 2, erlog.getOptions().length);
    assertEquals("Testing -verbose option", opts[0], erlog.getOptions()[0]);
    assertEquals("Testing -v option", opts[1], erlog.getOptions()[1]);
    // Testing an empty error logger option
    erlog = new ErrorLogger();
    assertSame("Testing empty option", null, erlog.getOptions());
  }
  
  /**
   * Test getArgs method.
   * 
   */
  @Test
  public void testGetArgs() {
    ErrorLogger erlog = new ErrorLogger(args);
    assertEquals("Testing arguments length", 4, erlog.getArgs().length);
    assertEquals("Testing arguments args[0]", args[0], erlog.getArgs()[0]);
    assertEquals("Testing arguments args[1]", args[1], erlog.getArgs()[1]);
    assertEquals("Testing arguments args[2]", args[2], erlog.getArgs()[2]);
    assertEquals("Testing arguments args[3]", args[3], erlog.getArgs()[3]);
    // Testing an empty error logger argument
    erlog = new ErrorLogger();
    assertSame("Testing empty args", null, erlog.getArgs());
  }
  
  /**
   * Test getParams method.
   * 
   */
  @Test
  public void testGetParams() {
    ErrorLogger erlog = new ErrorLogger(args);
    assertEquals("Testing arguments args[2]", args[2], erlog.getParams()[0]);
    assertEquals("Testing arguments args[3]", args[3], erlog.getParams()[1]);
  }
  
  /**
   * Test boolean option for verbose.
   */
  @Test
  public void testOptionIsVerbose() {  
    ErrorLogger erlog = new ErrorLogger(args);
    assertEquals("Testing verbose is on", true, erlog.isVerbose());
    String[] args2 = {"arg1", "arg2"};
    erlog = new ErrorLogger(args2);
    assertEquals("Testing verbose is off", false, erlog.isVerbose());
  }

}
